<template>
  <van-swipe :autoplay="3000" @change="onChange" :loop="false" :height="300">
    <van-swipe-item v-for="(image, index) in images" :key="index">
      <img v-lazy="image" />
    </van-swipe-item>
    <template #indicator>
      <div class="custom-indicator">{{ current + 1 }}/4</div>
    </template>
  </van-swipe>
</template>

<script>
import Vue from "vue";
import { Lazyload } from "vant";

Vue.use(Lazyload);
export default {
  props:["msg"],
  data() {
    return {
      images: [],
      current: 0,
    };
  },
  methods: {
    onChange(index) {
      this.current = index;
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.images = this.msg;
    });

    //         this.$http({
    //       url: "api/banner/list", // 设置请求的地址
    //       method: "GET", // 设置请求方法
    //     }).then((res) => {
    //       // res为后端返回的数据
    //       res.data.data.forEach(element => {
    //         this.images.push(element.img)
    //       });
    //     });
  },
};
</script>

<style scoped>
.custom-indicator {
  position: absolute;
  right: -10px;
  bottom: 5px;
  padding: 2px 20px 2px 10px;
  border-radius: 8px;
  font-size: 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.1);
}
* {
  margin: 0;
  padding: 0;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
img {
  /* width: 92vw; */
  width: 100%;
  /* height: 90.88888889vw; */
  height: 100%;
  /* margin-left: 4vw; */
  /* border-radius: 4vw; */
}

</style>